﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Search : Page
{
    protected SearchTags tags;
    protected string xmlFile = Utils.GetApplicationSetting(Constants.PHYSICAL_PATH) + "SearchTags.xml";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["q"]))
        {
            // adauga query-ul intr-o lista cu cele mai cautate cuvinte
            tags = new SearchTags(xmlFile);
            SearchTag tag = tags.FindTag(Server.UrlDecode(Request.QueryString["q"]));
            Title = Server.UrlDecode(Request.QueryString["q"]);

            if (tag.ID > 0)
            {
                tag.Occurances++;
            }
            else
            {
                tag.ID = (tags.List.Count > 0) ? ((SearchTag)tags.List[0]).ID + 1 : 1;
                tag.Title = Server.UrlDecode(Request.QueryString["q"]);
                tag.URL = Request.RawUrl;
                tags.Add(tag);
            }
            tags.SaveToXml(xmlFile);
        }

        if (Master != null)
        {
            var rightContentHolder = (ContentPlaceHolder)Master.FindControl("RightContentHolder");
            rightContentHolder.Visible = false;
        }
    }
}